<%@ page language="java" contentType="text/xml; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@page import="com.glowdayz.common.DBHandler"%>
<%@page import="com.glowdayz.common.ApiHandler"%>
<%@page import="com.glowdayz.common.ApiHandler.XmlData"%>
<%@page import="com.glowdayz.glowmee.cmd.RegisterCMD"%>
<%@page import="com.glowdayz.glowmee.dao.RegisterDAO"%>
<%@page import="java.util.ArrayList"%>
<%
	DBHandler.getInstance().connect();

	ApiHandler web = new ApiHandler(request, out, "JSPglowmee");
	
	String eMail = web.getValue("eMail");
	String password = web.getValue("password");
	String regId = web.getValue("regId");
	
	int registerCount = DBHandler.getInstance().getCount("register", "idRegister", "eMail='" + eMail + "'");
	
	if (registerCount < 1) {
		DBHandler.getInstance().disconnect();
		web.result(null, "가입되어 있지 않은 이메일입니다.");
		return;
	}
	
	RegisterCMD cmd = RegisterDAO.getInstance().doLogin(eMail, password);
	
	if (cmd == null) {
		DBHandler.getInstance().disconnect();
		web.result(null, "비밀번호를 다시한번 확인해주세요.");
		return;
	}
	
	if (regId != null && !regId.equals("")) {
		RegisterDAO.getInstance().updateRegId(cmd.getIdRegister(), regId);
	}
	
	DBHandler.getInstance().disconnect();
	
	ArrayList<XmlData> list = new ArrayList<XmlData>();
	list.add(new XmlData("seq", cmd.getIdRegister()));
	list.add(new XmlData("mail", eMail));
	list.add(new XmlData("nickName", cmd.getNickName()));
	web.result("SUCCESS", "로그인 되었습니다.", list);
%>